<?php

namespace App\Http\Controllers\Admin;

use App\Models\ApiUsers;
use Illuminate\Http\Request;

class ApiUserController extends BaseController
{
    /**
     * Display a listing of the resource.
     *接口账号列表显示
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //查询出账号的所有信息
        $data = ApiUsers::paginate($this->pagesize);
        return view('admin.apiuser.index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('admin.apiuser.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $postData = $this->validate($request,[
            'username' => 'required|unique:api_users,username',
            'password' => 'required'
        ]);
        //验证成功直接入库   但是在入库之前要对密码进行加密处理
        // $postData['password'] = bcrypt($postData['password']);
        ApiUsers::create($postData);
        return redirect(route('admin.apiuser.create'))->with('success','接口账号添加成功');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
